﻿using System;
using xml = System.Xml;
using System.Xml.Serialization;
using System.ComponentModel;

namespace Sixeyed.CacheAdapter.Configuration
{
    /// <summary>
    /// Represents configured cache properties for a type of message
    /// </summary>
    [XmlRoot(ElementName = "messageCacheConfiguration", Namespace = "http://schemas.sixeyed.com/CacheAdapter/2009")]    
    public partial class MessageCacheConfiguration
    {
        private string _messageType;
        private TimeSpan _cacheLifespan = TimeSpan.Zero;

        /// <summary>
        /// BizTalk message type - http://namespace#RootElementName
        /// </summary>
        [XmlElement("messageType", IsNullable = false)]
        public string MessageType
        {
            get { return this._messageType; }
            set { this._messageType = value; }
        }

        /// <summary>
        /// Gets/sets an XML representation of the cache lifespan for the message type
        /// </summary>
        [Browsable(false)]
        [XmlElement("cacheLifespan", IsNullable = true)]
        public string CacheLifespanXml
        {
            get { return xml.XmlConvert.ToString(this._cacheLifespan); }
            set { this._cacheLifespan = xml.XmlConvert.ToTimeSpan(value); }
        }

        /// <summary>
        /// Gets/sets the cache lifespan for the message type
        /// </summary>
        [XmlIgnore]        
        public TimeSpan CacheLifespan
        {
            get { return this._cacheLifespan; }
            set { this._cacheLifespan = value; }
        }
    }
}
